package com.sh.data.engine.web.config;

import com.sh.data.engine.common.constants.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.core.customizers.OpenApiCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: mengzheng.mhc
 * @date: 2024/12/6 16:08
 */
@Slf4j
@Configuration
public class OpenApiConfig {

    @Bean
    public OpenApiCustomizer customizeGlobalHeaders() {
        return openApi ->
            openApi.getPaths().forEach((path, pathItem) -> {
                if (path.startsWith("/openapi")) {
                    if (path.startsWith("/openapi/project") && !path.startsWith("/openapi/project/role")) {
                        return;
                    }

                    pathItem.readOperations().forEach(operation ->
                        operation.addParametersItem(new io.swagger.v3.oas.models.parameters.Parameter()
                            .name(Constants.HEADER_PROJECT_ID)
                            .in("header")
                            .required(true)
                            .description("工作空间id")));
                }
            });
    }
}
